using System;
using System.Collections.Generic;
/// <summary>
/// AbsHFMetaObject【IHFSynchronize接口】
/// </summary>
public partial class AbsHFMetaObject : IHFSynchronize
{
    #region IHFISynchronize
    /// <summary>
    /// 导出同步数据
    /// </summary>
    /// <returns>同步数据</returns>
    public List<byte> ExportSynchronize()
    {
        List<byte> sers = new List<byte>();
        OnBeforeExportSynchronize(this, sers);        
        sers.AddRange(OnExportSynchronize());       
        OnAfterExportSynchronize(this, sers);
        return sers;
    }

    /// <summary>
    /// 导出同步之前事件处理
    /// </summary>
    /// <param name="_self">同步对象</param>
    /// <param name="_bytes">同步数据</param>
    protected virtual void OnBeforeExportSynchronize(IHFSynchronize _self, List<byte> _bytes) { } 
    /// <summary>
    /// 导出同步数据
    /// </summary>
    /// <returns>同步数据</returns>
    protected virtual byte[] OnExportSynchronize() { return new byte[0]; }
    /// <summary>
    /// 导出同步之后事件处理
    /// </summary>
    /// <param name="_self">同步对象</param>
    /// <param name="_bytes">同步数据</param>
    protected virtual void OnAfterExportSynchronize(IHFSynchronize _self, List<byte> _bytes) { }


    /// <summary>
    /// 导入同步数据
    /// </summary>
    /// <param name="_data">同步数据</param>
    /// <param name="_startIndex">起始索引</param>
    /// <returns>结束索引</returns>
    public int ImportSynchronize(byte[] _data, int _startIndex)
    {
        OnBeforeImportSynchronize(this, _data, _startIndex);
        mGlobalId = _data.HFToInt32(ref _startIndex);
        _startIndex = OnImportSynchronize(_data, _startIndex);
        OnAfterImportSynchronize(this, _data, _startIndex);
        return _startIndex;
    }
    /// <summary>
    /// 导入同步之前事件处理
    /// </summary>
    /// <param name="_self">同步对象</param>
    /// <param name="_bytes">同步数据</param>
    /// <param name="_startIndex">起始索引</param>
    protected virtual void OnBeforeImportSynchronize(IHFSynchronize _self, byte[] _bytes,int _startIndex) { }
    /// <summary>
    /// 导入同步数据
    /// </summary>
    /// <param name="_data">同步数据</param>
    /// <param name="_startIndex">起始索引</param>
    /// <returns>结束索引</returns>
    protected virtual int OnImportSynchronize(byte[] _data, int _startIndex) { return _startIndex; }
    /// <summary>
    /// 导入同步之后事件处理
    /// </summary>
    /// <param name="_self">同步对象</param>
    /// <param name="_bytes">同步数据</param>
    /// <param name="_startIndex">起始索引</param>
    protected virtual void OnAfterImportSynchronize(IHFSynchronize _self, byte[] _bytes, int _startIndex) { }
    #endregion
}
